package com.veo.exception;

import lombok.SneakyThrows;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//自定义全局处理的异常
@Component
//定义调用的顺序最高，数字越小，优先级越高
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class CustomerExceptionHandlerResolver implements HandlerExceptionResolver {
    @SneakyThrows
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse,
                                         Object o, Exception e) {
        httpServletResponse.sendError(511,"我的错误页面");
        return null;
    }
}
